<!DOCTYPE html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>

// From public/mojom/web_feature/web_feature.mojom
const kEarlyHintsPreloadUseCounter = 3967;

async_test((t) => {
    const image = document.createElement('img');
    image.src = "blue-cacheable.png";
    image.onload = t.step_func_done(() => {
        const name = new URL("blue-cacheable.png", window.location);
        const entry = performance.getEntriesByName(name);
        assert_equals(entry.length, 1);
        assert_equals(entry[0].initiatorType, "early-hints");
        assert_true(internals.isUseCounted(document, kEarlyHintsPreloadUseCounter));
    });
    document.body.appendChild(image);
}, "Ensure initiatorType is set to 'early-hints'");
</script>
</body>
